﻿using FreeSql.DataAnnotations;
using Jumei.Common.BaseModel;
using Jumei.Model.Business.MemberManage;
using System;

namespace Jumei.Model.Business.OrdersManage
{
    /// <summary>
    /// 订单表
    /// </summary>
	[Table(Name = "mb_orders")]
    [Index("idx_{tablename}_01", nameof(OrderNo) + "," + nameof(TenantId), true)]
    [Index("idx_{tablename}_02", nameof(OrderType), false)]
    [Index("idx_{tablename}_03", nameof(TradeType), false)]
    [Index("idx_{tablename}_04", nameof(StoreType), false)]
    [Index("idx_{tablename}_05", nameof(TradeNo), false)]
    [Index("idx_{tablename}_06", nameof(ReceiverName), false)]
    [Index("idx_{tablename}_07", nameof(ReceiverPhone), false)]
    public class OrdersEntity : EntityFull, ITenant
    {
        /// <summary>
        /// 租户Id
        /// </summary>
        [Column(Position = -10)]
        public long? TenantId { get; set; }

        /// <summary>
        /// 订单号
        /// </summary>
        [Column(StringLength = 20)]
        public string OrderNo { get; set; }

        /// <summary>
        /// 店铺ID
        /// </summary>
        public long ShopId { get; set; }

        /// <summary>
        /// 会员Id
        /// </summary>
        public long MemberId { get; set; }

        public MemberEntity Member { get; set; }

        /// <summary>
        /// 订单状态 
        /// -3:用户拒收 
        /// -2:未付款的订单 
        /// -1：用户取消 
        /// 0:待发货 
        /// 1:配送中 
        /// 2:用户确认收货
        /// </summary>
        public int OrderStatus { get; set; } = -2;

        /// <summary>
        /// 商品总金额 
        /// 商品总价格--未进行任何折扣的总价格
        /// </summary>
        public decimal GoodsMoney { get; set; }

        /// <summary>
        /// 收货方式
        /// 0:送货上门 
        /// 1:自提
        /// </summary>
        public int DeliverType { get; set; }

        /// <summary>
        /// 运费
        /// 运费规则按照每家店的规则算。
        /// </summary>
        public decimal DeliverMoney { get; set; }

        /// <summary>
        /// 订单总金额
        /// 包括运费
        /// </summary>
        public decimal TotalMoney { get; set; }

        /// <summary>
        /// 实际订单总金额	
        /// 进行各种折扣之后的金额
        /// </summary>
        public decimal RealTotalMoney { get; set; }

        /// <summary>
        /// 支付方式
        /// 0:货到付款
        /// 1:在线支付
        /// </summary>
        public int PayType { get; set; }

        /// <summary>
        /// 支付来源代码
        /// 支付来源代码，和支付方式对应代码
        /// </summary>
        public int PayFrom { get; set; }

        /// <summary>
        /// 是否支付
        /// 0:未支付 1:已支付
        /// </summary>
        public bool IsPay { get; set; }

        /// <summary>
        /// 最后一级区域Id
        /// </summary>
        public int AreaId { get; set; }

        /// <summary>
        /// 区域Id路径 省级id_市级id_县级Id_ 例如:110000_110100_110101_
        /// </summary>
        [Column(StringLength = 255)]
        public string AreaIdPath { get; set; }

        /// <summary>
        ///收货人名称
        /// </summary>
        [Column(StringLength = 50)]
        public string ReceiverName { get; set; }

        /// <summary>
        ///收件人地址
        /// </summary>
        [Column(StringLength = 50)]
        public string ReceiverAddress { get; set; }

        /// <summary>
        ///收件人手机
        /// </summary>
        [Column(StringLength = 50)]
        public string ReceiverPhone { get; set; }

        /// <summary>
        /// 所得积分
        /// </summary>
        public int OrderScore { get; set; }

        /// <summary>
        /// 是否需要发票 
        /// </summary>
        public bool IsInvoice { get; set; }

        /// <summary>
        ///发票抬头
        /// </summary>
        [Column(StringLength = 255)]
        public string InvoiceClient { get; set; }

        /// <summary>
        ///订单备注
        /// </summary>
        [Column(StringLength = 255)]
        public string OrderRemarks { get; set; }

        /// <summary>
        ///订单来源 	0:商城 1:微信 2:手机版 3:安卓App 4:苹果App 5:小程序
        /// </summary>
        public int OrderSource { get; set; }

        /// <summary>
        ///	需缴费用
        /// </summary>
        public decimal NeedPay { get; set; }

        /// <summary>
        ///	是否退款
        /// </summary>
        public bool IsRefund { get; set; } = false;

        /// <summary>
        ///	是否点评
        /// </summary>
        public bool? IsAppraise { get; set; }

        /// <summary>
        /// 取消原因ID
        /// </summary>
        public long? CancelReasonId { get; set; }

        /// <summary>
        /// 拒收原因ID
        /// </summary>
        public long? RejectOtherReasonId { get; set; }

        /// <summary>
        ///	是否订单已完结 未完结 已完结
        /// </summary>
        public bool IsClosed { get; set; } = false;

        /// <summary>
        /// 订单备注
        /// </summary>
        [Column(StringLength = -2)]
        public string GoodsSearchKeys { get; set; }

        /// <summary>
        /// 订单流水号
        /// </summary>
        [Column(StringLength = 50)]
        public string Orderunique { get; set; }

        /// <summary>
        /// 收货时间
        /// </summary>
        public DateTime? ReceiveTime { get; set; }

        /// <summary>
        /// 发货时间
        /// </summary>
        public DateTime? DeliveryTime { get; set; }

        /// <summary>
        /// 在线支付交易流水	
        /// </summary>
        [Column(StringLength = 100)]
        public string TradeNo { get; set; }

        /// <summary>
        ///	订单有效标志
        /// </summary>
        public bool DataFlag { get; set; } = true;

        /// <summary>
        /// 是否结算，大于0的话则是结算ID
        /// </summary>
        public long? SettlementId { get; set; }

        /// <summary>
        ///	订单应收佣金	
        /// </summary>
        public decimal? CommissionFee { get; set; }

        /// <summary>
        /// 支付自增ID 和订单号组合用，方便多次修改价格生成新的订单号
        /// </summary>
        public long? PayRandId { get; set; }

        /// <summary>
        /// 订单类型  0:实物订单 1:非实物订单（非实物订单不享受任何折扣）
        /// </summary>
        public int OrderType { get; set; }

        /// <summary>
        /// 积分抵扣的金额	
        /// </summary>
        public decimal? ScoreMoney { get; set; }

        /// <summary>
        /// 用于抵扣的积分	
        /// </summary>
        public int? UseScore { get; set; }

        /// <summary>
        /// 订单代码 默认为order。如果是插件产生的订单则这里用于标记是那些插件
        /// </summary>
        [Column(StringLength = 50)]
        public string OrderCode { get; set; } = "order";

        /// <summary>
        /// 订单备注，用于辅助插件
        /// </summary>
        [Column(StringLength = -2)]
        public string ExtraJson { get; set; }

        /// <summary>
        /// 订单类型	 1：按商品设置提取佣金 2：按订单比例提取佣金
        /// </summary>
        public int? DistributType { get; set; }

        /// <summary>
        /// 分成比例  如：30:20:50
        /// </summary>
        public int? DistributOrderRate { get; set; }

        /// <summary>
        /// 订单佣金占订单百分比
        /// </summary>
        [Column(StringLength = 20)]
        public string DistributRate { get; set; }

        /// <summary>
        /// 分成佣金	
        /// </summary>
        [Column(StringLength = 20)]
        public decimal TotalCommission { get; set; } = 0;

        /// <summary>
        /// 订单来源表自增ID  和orderCode对应，凡是插件产生的订单，这个地方就记录该插件表的自增ID，以便回查记录
        /// </summary>
        public long? OrderCodeTargetId { get; set; }

        /// <summary>
        ///	提醒发货 
        ///	false:未提醒 
        ///	true:已提醒
        /// </summary>
        public bool NoticeDeliver { get; set; } = false;

        /// <summary>
        /// 发票信息json
        /// </summary>
        [Column(StringLength = -2)]
        public string InvoiceJson { get; set; }

        /// <summary>
        /// 所使用的充值送金额
        /// </summary>
        public decimal? LockCashMoney { get; set; }

        /// <summary>
        /// 所使用的优惠券ID
        /// </summary>
        public long? UserCouponId { get; set; }

        /// <summary>
        /// 所使用的优惠券记录json
        /// </summary>
        [Column(StringLength = -2)]
        public string UserCouponJson { get; set; }

        /// <summary>
        /// 付款时间
        /// </summary>
        public DateTime? PayTime { get; set; }

        /// <summary>
        /// 是否批量提交订单	
        /// </summary>
        public bool? IsBatch { get; set; }

        /// <summary>
        /// 用于退款的订单支付总金额
        /// </summary>
        public decimal? TotalPayFee { get; set; }

        /// <summary>
        /// 收银员ID
        /// </summary>
        public long? ShopUserId { get; set; }

        /// <summary>
        /// 收银类型
        /// 1：收银系统 
        /// 0：普通收银
        /// </summary>
        public int TradeType { get; set; } = 0;

        /// <summary>
        /// 余额支付金额
        /// </summary>
        public decimal BalancePay { get; set; } = 0;

        /// <summary>
        /// 是否已经开发票
        /// </summary>
        public bool IsMakeInvoice { get; set; } = false;

        /// <summary>
        /// 售后结束时间,确认收货时间+后台设置的售后有效天数
        /// </summary>
        public DateTime? AfterSaleEndTime { get; set; }

        /// <summary>
        /// 获得的积分数可抵扣的金额
        /// </summary>
        public decimal GetScoreVal { get; set; } = 0;

        /// <summary>
        /// 分销佣金是否结算
        /// </summary>
        public bool DmoneyIsSettlement { get; set; } = false;

        /// <summary>
        /// 自提点ID
        /// 1：商家自提点 
        /// 2：平台自提点
        /// </summary>
        public int StoreType { get; set; } = 0;

        /// <summary>
        /// 门店ID
        /// </summary>
        public long StoreId { get; set; }

        /// <summary>
        /// 核销码 
        /// 自提商品才有
        /// </summary>
        public string VerificationCode { get; set; }

        /// <summary>
        /// 核销时间
        /// </summary>
        public DateTime? VerificationTime { get; set; }

        /// <summary>
        /// 已退款支付金额	
        /// </summary>
        public decimal RefundedPayMoney { get; set; } = 0;

        /// <summary>
        /// 经销商ID	
        /// </summary>
        public long DealerId { get; set; }
    }
}
